# -*- coding: utf-8 -*-
# !/usr/bin/env python
from utils.mysql_utils import query_to_list


def query_host_info(host_id=''):
    sql_parameter = []

    if host_id:
        sql_fragment = "WHERE a.host_id = %s"
        sql_parameter.append(host_id)
    else:
        sql_fragment = ''

    sql = """
    SELECT *
    FROM hosts_management a
    %s
    AND a.status != 0
    """%sql_fragment
    data = query_to_list(sql, sql_parameter, True)

    return data


def get_host_resource_user(host_id='', resource_user_permission_code=''):
    sql_parameter = [host_id]

    if resource_user_permission_code:
        sql_fragment = "AND b.resource_user_default = %s"
        sql_parameter.append(resource_user_permission_code)
    else:
        sql_fragment = "AND b.resource_user_default = 1"

    sql = """
    SELECT *
    FROM hosts_management a
    LEFT JOIN resource_user b ON a.resource_user_ids = b.resource_user_ids
    WHERE a.host_id = %s
    %s
    """%sql_fragment
    data = query_to_list(sql, sql_parameter, True)

    return data